package com.example.controller;

import com.example.base.domain.User;
import com.example.service.ZhiHuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("test")
public class TestController {

    @Resource
    private ZhiHuService zhiHuService;

    private static Logger logger = LoggerFactory.getLogger(TestController.class);

    /**
     * 全量同步
     */
    @GetMapping("/sync/zhiHu")
    public void syncZhiHuJob() {
        logger.info("syncZhiHuJob start");

        /*同步知乎文章数据*/
        zhiHuService.syncArticle();

        /*同步知乎回答数据*/
       zhiHuService.syncAnswer();

        /*同步趋势*/
        zhiHuService.syncTrend();

        /*同步粉丝数据*/
        zhiHuService.syncFans();


        logger.info("syncZhiHuJob end");
    }

    /**
     * 单知乎账号数据同步
     * @param user
     */
    @GetMapping("/sync/zhiHu/{user}")
    public void syncZhiHuJobForUser(@PathVariable String user) {
        logger.info("syncZhiHuJob user start:" + user);

        /*同步知乎数据*/
        zhiHuService.syncZhiHuJobForUser(user);

        logger.info("syncZhiHuJob user end:" + user);
    }

    /**
     * 创建或更新知乎账号数据
     * @param user
     */
    @PostMapping(value = "/create/user")
    public void createUser(@RequestBody User user) {
        logger.info("createUser start:" + user);

        zhiHuService.createUser(user);

        logger.info("createUser end:" + user);
    }
}
